import { Storage } from './storage'

export function getToken() {
  return Storage.getSession('token')
}
export function getAccount() {
  return Storage.getSession('account')
}

export function setToken(token) {
  Storage.setSession({
    key: 'token',
    value: token
  })
}
export function setAccount(account) {
  Storage.setSession({
    key: 'account',
    value: account
  })
}
export function removeToken() {
  Storage.removeSession('token')
}

export function permsJudge(value) {
  let Perms = []
  JSON.parse(sessionStorage.getItem('menu') || '[]').forEach((e) => {
    Perms.push(e.id)
    e.children.forEach((ce) => {
      Perms.push(ce.id)
    })
  })
  for (let item of Perms) {
    if (item === value) {
      return true
    }
  }
  return false
}
